package com.huopaolan.yohuoshop.Mvp.Presenter;

import com.huopaolan.lib_core.Mvp.Presenter.BasePresenter;
import com.huopaolan.yohuoshop.Bean.ShoppingTrolleyEntity;
import com.huopaolan.yohuoshop.Mvp.Contract.ShoppingTrolleyContract;

import org.json.JSONException;
import org.json.JSONObject;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class ShoppingTrolleyPresenter extends BasePresenter<ShoppingTrolleyContract.ShoppingTrolleyIView, ShoppingTrolleyContract.ShoppingTrolleyIModel> {
    @Inject
    public ShoppingTrolleyPresenter(ShoppingTrolleyContract.ShoppingTrolleyIView shoppingTrolleyIView, ShoppingTrolleyContract.ShoppingTrolleyIModel shoppingTrolleyIModel) {
        super(shoppingTrolleyIView, shoppingTrolleyIModel);
    }

    public void ShoppingTrolleyRequest() {
        JSONObject shopping_list = new JSONObject();
        try {
            shopping_list.put("userid", "1");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String request = shopping_list.toString();
        m.shoppingTrolley_request(request).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ShoppingTrolleyEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ShoppingTrolleyEntity entity) {
                        v.ShoppingTrolleySuccess(entity);
                        buildEntity(entity);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    //分解
    private void buildEntity(ShoppingTrolleyEntity entity) {

    }
}
